package com.fund.security.context;

import org.springframework.context.annotation.Bean;

public class ContextHolder {


    private ContextHolder(){
    }

    @Bean
    public static ContextHolder getContextHolder(){
        return new ContextHolder();
    }

    /**
     * 用户信息存入线程
     */
    private ThreadLocal<UserContext> contextThreadLocal = new ThreadLocal();

    /**
     * 获取上下文
     * @return Context
     */
    public UserContext getContext(){
        return contextThreadLocal.get();
    }

    public void clearContext(){
        this.contextThreadLocal.remove();
    }

    public void put(UserContext userContext){
        this.contextThreadLocal.set(userContext);
    }
}
